require("Scripts/Common/Class")
require("Scripts/Common/Utility")

LoopSystem = Class()

function LoopSystem:Ctor()
	self._loop_updaters = {}
end

function LoopSystem:AddUpdater(updater)
	if updater == nil then return end
	if self._loop_updaters[updater] then return end
	self._loop_updaters[updater] = updater
end

function LoopSystem:RemoveUpdater(updater)
	if updater == nil then return end
	self._loop_updaters[updater] = nil
end

function LoopSystem:Update(frame_time)
	local remove_list = {}
	for updater_k, updater_v in pairs(self._loop_updaters) do
		updater_v:Update(frame_time)
		if updater_v:IsCompleted() then
			remove_list[updater_v] = updater_v
		end
	end
	for k, v in pairs(remove_list) do
		self._loop_updaters[v] = nil
	end
end

g_LoopSystem = LoopSystem()

function Global_Update(frame_time)
	g_LoopSystem:Update(frame_time)
end
